<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<!--session-storage 浏览器一关就结束-->
<body>
        <h2>session-storage</h2>
        <button onclick="saveData()">点我保存一个数据</button>
        <button onclick="readData()">点我读取一个数据</button>
        <button onclick="deleteData()">点我删除一个数据</button>
        <button onclick="deleteALLData()">点我清空一个数据</button>
</body>
<script>

</script>
</html>
<script>
    let p = {name:'张三',age:18}
    //保存
    function saveData(){
        //                           key   value 都是字符串
        window.sessionStorage.setItem('msg','hello')
        window.sessionStorage.setItem('person',JSON.stringify(p))
    }
    //读取
    function readData(){
        console.log(sessionStorage.getItem('msg'))

        const result = sessionStorage.getItem('person')
    //    转成对象类型
        console.log(JSON.parse(result))
    }
    //删除
    function deleteData(){
        sessionStorage.removeItem('msg')
    }
    function deleteALLData(){
        sessionStorage.clear()
    }
</script>